/*! MAIN */
#include <iostream>
#include <string>
#include <iomanip>
#include <clocale>
#include "Bit.h"
#include "Bitstr.h"
#include "Omvandla.h"

using namespace std;

/* Test for all bit operations */
int main1()
{
	Bit bit;
	char a = '0';
	char b = '1';
	cout << "*Test of logical operations*" << endl;
	cout << bit.and(a,b) << endl;
	cout << bit.or(a,b) << endl;
	cout << bit.xor(a,b) << endl;
	cout << bit.nor(a,b) << endl;
	cout << bit.not(a) << endl;
	cout << bit.not(b) << endl;
	return 0;
}

/* Test for the two-complement-function */
int main2()
{
	cout << "*Test of two-complement*" << endl;
	Bitstr bitstr;
	string str = "10011100";
	bitstr.twoComplement(str);
	cout << str << endl;
	return 0;
}

/* Test for tal_str() */
int main3()
{
	cout << "*Test convert*" << endl;
	Omvandlare omvandlare;
	string str;
	omvandlare.tal_str(-4, str, 5);
	cout << str << endl;
	return 0;
}

/* Test for addStr() */
int main4()
{
	cout << "*Binary addition test*" << endl;
	Bitstr bitstr;
	string sum;
	bitstr.addStr("0001", "0010", sum);
	cout << sum << endl << endl;
	return 0;
}

/* DigSim, this is the main-program */
int main()
{
	main1();
	main2();
	main3();
	main4();
	Bitstr bitstr;
	Omvandlare omvandlare;
	int int1, int2, nrbits;
	string str1, str2, sumstr;

	cout << "<*-*-*-*-*>-DIGSIM-<*-*-*-*-*>" << endl << endl;
	cout << "Enter two decimal numbers that you want to add." << endl;
	cout << "Number 1: ";
	cin >> int1;
	cout << "Number 2: ";
	cin >> int2;
	cout << "Enter the amount of bits that should be used: ";
	cin >> nrbits;

	bitstr.addStr(omvandlare.tal_str(int1, str1, nrbits), omvandlare.tal_str(int2, str2, nrbits), sumstr);
	
	cout << sumstr;
	cout << endl << endl;
	cout << omvandlare.convertBinToDec(sumstr);

	cin.ignore();
	cin.get();
}